package com.ruoyi.tsjData.service.impl;

import com.alibaba.fastjson2.JSON;
import com.ruoyi.common.core.pad.ChartLineDTO;
import com.ruoyi.common.core.pad.LinePoint;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.calculate.BezierCurveUtil;
import com.ruoyi.tsjData.domain.plat.DataTshjTyxn;
import com.ruoyi.tsjData.domain.plat.DataTshjTyxnModify;
import com.ruoyi.tsjData.domain.plat.TshjTyxnJs;
import com.ruoyi.tsjData.mapper.DataTshjTyxnMapper;
import com.ruoyi.tsjData.service.IDataTshjTyxnService;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.concurrent.Future;


/**
 * 提升机-调压性能测试Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-10-25
 */
@Service
public class DataTshjTyxnServiceImpl implements IDataTshjTyxnService
{
    @Autowired(required = false)
    private DataTshjTyxnMapper dataTshjTyxnMapper;

    protected org.slf4j.Logger log = LoggerFactory.getLogger(DataTshjTyxnServiceImpl.class);

    /**
     * 查询提升机-调压性能测试
     * 
     * @param tyxnId 提升机-调压性能测试主键
     * @return 提升机-调压性能测试
     */
    @Override
    public DataTshjTyxn selectDataTshjTyxnByTyxnId(Long tyxnId)
    {
        return dataTshjTyxnMapper.selectDataTshjTyxnByTyxnId(tyxnId);
    }

    /**
     * 调压性能数据
     * @param dataTaskId
     * @return
     */
    @Async("threadPoolKy")
    @Override
    public Future<List<DataTshjTyxn>> selectTyxn(Long dataTaskId) {
        List<DataTshjTyxn> dataTshjTyxnEntities = dataTshjTyxnMapper.selectDataTshjTyxnByDataTaskId(dataTaskId);
        if (!dataTshjTyxnEntities.isEmpty()) {
            dataTshjTyxnEntities.forEach(item -> {
                item.setYy1ChartLineDTO(BezierCurveUtil.calPoints(item.getYyList1(), 0.2f, false));
                item.setYy2ChartLineDTO(BezierCurveUtil.calPoints(item.getYyList2(), 0.2f, false));
                item.setDlChartLineDTO(BezierCurveUtil.calPoints(item.getDlList(), 0.2f, false));
                item.setDyChartLineDTO(BezierCurveUtil.calPoints(item.getDyList(), 0.2f, false));
            });
            //获取1号液压站和2号液压站的计算前后半段数据
            Map<String, ChartLineDTO> yhMap;
            Map<String, ChartLineDTO> ehMap;
            for(DataTshjTyxn dataTshjTyxn : dataTshjTyxnEntities) {
                //获取1号液压站数据
                if(StringUtils.equals("1", dataTshjTyxn.getYyzh())) {
                    yhMap =  calFunc(dataTshjTyxn);
                    if(!yhMap.isEmpty()) {
                        TshjTyxnJs tshjTyxnJs = new TshjTyxnJs();
                        tshjTyxnJs.setTyxnId(dataTshjTyxn.getTyxnId());
                        tshjTyxnJs.setZhadl(dataTshjTyxn.getZhadl());
                        tshjTyxnJs.setYy1BeforeLineDTO(yhMap.get("yy1BeforeLine"));
                        tshjTyxnJs.setYy1AfterLineDTO(yhMap.get("yy1AfterLine"));
                        tshjTyxnJs.setYy2BeforeLineDTO(yhMap.get("yy2BeforeLine"));
                        tshjTyxnJs.setYy2AfterLineDTO(yhMap.get("yy2AfterLine"));
                        dataTshjTyxn.setTshjTyxnJs(tshjTyxnJs);
                    }
                }
                //获取2号液压站数据
                if(StringUtils.equals("2", dataTshjTyxn.getYyzh())) {
                    ehMap =  calFunc(dataTshjTyxn);
                    if(!ehMap.isEmpty()) {
                        TshjTyxnJs tshjTyxnJs = new TshjTyxnJs();
                        tshjTyxnJs.setTyxnId(dataTshjTyxn.getTyxnId());
                        tshjTyxnJs.setZhadl(dataTshjTyxn.getZhadl());
                        tshjTyxnJs.setYy1BeforeLineDTO(ehMap.get("yy1BeforeLine"));
                        tshjTyxnJs.setYy1AfterLineDTO(ehMap.get("yy1AfterLine"));
                        tshjTyxnJs.setYy2BeforeLineDTO(ehMap.get("yy2BeforeLine"));
                        tshjTyxnJs.setYy2AfterLineDTO(ehMap.get("yy2AfterLine"));
                        dataTshjTyxn.setTshjTyxnJs(tshjTyxnJs);
                    }
                }
            }
        }
        //拼接返回结果
        return new AsyncResult<>(dataTshjTyxnEntities);
    }

    /**
     * 根据调压性能id获取油压差
     * @param tyxn1
     * @param tyxn2
     * @return
     */
    @Override
    public Map<String, Object> getTyxnYycha(Long tyxn1, Long tyxn2) {
        DataTshjTyxn dataTshjTyxn1 = dataTshjTyxnMapper.selectDataTshjTyxnByTyxnId(tyxn1);
        DataTshjTyxn dataTshjTyxn2 = dataTshjTyxnMapper.selectDataTshjTyxnByTyxnId(tyxn2);
        //获取1号液压站和2号液压站的计算前后半段数据
        Map<String, ChartLineDTO> yhMap = new HashMap<>();
        Map<String, ChartLineDTO> ehMap = new HashMap<>();
        //获取1号液压站数据
        if(StringUtils.equals("1", dataTshjTyxn1.getYyzh())) {
            yhMap =  calFunc(dataTshjTyxn1);
            if(!yhMap.isEmpty()) {
                TshjTyxnJs tshjTyxnJs = new TshjTyxnJs();
                tshjTyxnJs.setTyxnId(dataTshjTyxn1.getTyxnId());
                tshjTyxnJs.setZhadl(dataTshjTyxn1.getZhadl());
                tshjTyxnJs.setYy1AfterLineDTO(yhMap.get("yy1BeforeLine"));
                tshjTyxnJs.setYy1AfterLineDTO(yhMap.get("yy1AfterLine"));
                tshjTyxnJs.setYy2BeforeLineDTO(yhMap.get("yy2BeforeLine"));
                tshjTyxnJs.setYy2AfterLineDTO(yhMap.get("yy2AfterLine"));
                dataTshjTyxn1.setTshjTyxnJs(tshjTyxnJs);
            }
        }
        //获取2号液压站数据
        if(StringUtils.equals("2", dataTshjTyxn2.getYyzh())) {
            ehMap =  calFunc(dataTshjTyxn2);
            if(!yhMap.isEmpty()) {
                TshjTyxnJs tshjTyxnJs = new TshjTyxnJs();
                tshjTyxnJs.setTyxnId(dataTshjTyxn2.getTyxnId());
                tshjTyxnJs.setZhadl(dataTshjTyxn2.getZhadl());
                tshjTyxnJs.setYy1AfterLineDTO(yhMap.get("yy1BeforeLine"));
                tshjTyxnJs.setYy1AfterLineDTO(yhMap.get("yy1AfterLine"));
                tshjTyxnJs.setYy2BeforeLineDTO(yhMap.get("yy2BeforeLine"));
                tshjTyxnJs.setYy2AfterLineDTO(yhMap.get("yy2AfterLine"));
                dataTshjTyxn2.setTshjTyxnJs(tshjTyxnJs);
            }
        }
        //拼接返回结果
        Map<String, Object> tshjTyxnMap = new HashMap<>();
        //合并x轴上电流电压数据
        try {
            List<Float> pointXList = mergeDldyList(yhMap.get("yy1BeforeLine"), yhMap.get("yy1AfterLine"), yhMap.get("yy2BeforeLine"), yhMap.get("yy2AfterLine"), ehMap.get("yy1BeforeLine"), ehMap.get("yy1AfterLine"), ehMap.get("yy2BeforeLine"), ehMap.get("yy2AfterLine"));
            Map<String, Float> yjMap = findYyChzhFunc(pointXList, yhMap.get("yy1BeforeLine"), yhMap.get("yy1AfterLine"), ehMap.get("yy1BeforeLine"), ehMap.get("yy1AfterLine"));
            Map<String, Float> ejMap = findYyChzhFunc(pointXList, yhMap.get("yy2BeforeLine"), yhMap.get("yy2AfterLine"), ehMap.get("yy2BeforeLine"), ehMap.get("yy2AfterLine"));
            //拼接返回结果
            tshjTyxnMap = new HashMap<>();
            tshjTyxnMap.put("yjMap", yjMap);
            tshjTyxnMap.put("ejMap", ejMap);
            return tshjTyxnMap;
        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            return tshjTyxnMap;
        }
    }

    /**
     * 调压性能获取差值图
     *
     * @param tyxn1
     * @param tyxn2
     */
    @Override
    public List<TshjTyxnJs> getTshjTyxnJs(Long tyxn1, Long tyxn2) {
        //获取调压性能数据
        DataTshjTyxn dataTshjTyxn1 = dataTshjTyxnMapper.selectDataTshjTyxnByTyxnId(tyxn1);
        DataTshjTyxn dataTshjTyxn2 = dataTshjTyxnMapper.selectDataTshjTyxnByTyxnId(tyxn2);
        List<DataTshjTyxn> dataTshjTyxnList = new ArrayList<>();
        if(dataTshjTyxn1 != null) {
            dataTshjTyxnList.add(dataTshjTyxn1);
        }
        if(dataTshjTyxn2 != null) {
            dataTshjTyxnList.add(dataTshjTyxn2);
        }
        //获取1号液压站和2号液压站的计算前后半段数据
        Map<String, ChartLineDTO> yhMap;
        Map<String, ChartLineDTO> ehMap;
        List<TshjTyxnJs> tshjTyxnJsList = new ArrayList<>();
        for(DataTshjTyxn dataTshjTyxn : dataTshjTyxnList) {
            //获取1号液压站数据
            if(StringUtils.equals("1", dataTshjTyxn.getYyzh())) {
                yhMap =  calFunc(dataTshjTyxn);
                if(!yhMap.isEmpty()) {
                    TshjTyxnJs tshjTyxnJs = new TshjTyxnJs();
                    tshjTyxnJs.setTyxnId(dataTshjTyxn.getTyxnId());
                    tshjTyxnJs.setZhadl(dataTshjTyxn.getZhadl());
                    tshjTyxnJs.setYy1BeforeLineDTO(yhMap.get("yy1BeforeLine"));
                    tshjTyxnJs.setYy1AfterLineDTO(yhMap.get("yy1AfterLine"));
                    tshjTyxnJs.setYy2BeforeLineDTO(yhMap.get("yy2BeforeLine"));
                    tshjTyxnJs.setYy2AfterLineDTO(yhMap.get("yy2AfterLine"));
                    tshjTyxnJsList.add(tshjTyxnJs);
                }
            }
            //获取2号液压站数据
            if(StringUtils.equals("2", dataTshjTyxn.getYyzh())) {
                ehMap =  calFunc(dataTshjTyxn);
                if(!ehMap.isEmpty()) {
                    TshjTyxnJs tshjTyxnJs = new TshjTyxnJs();
                    tshjTyxnJs.setTyxnId(dataTshjTyxn.getTyxnId());
                    tshjTyxnJs.setZhadl(dataTshjTyxn.getZhadl());
                    tshjTyxnJs.setYy1BeforeLineDTO(ehMap.get("yy1BeforeLine"));
                    tshjTyxnJs.setYy1AfterLineDTO(ehMap.get("yy1AfterLine"));
                    tshjTyxnJs.setYy2BeforeLineDTO(ehMap.get("yy2BeforeLine"));
                    tshjTyxnJs.setYy2AfterLineDTO(ehMap.get("yy2AfterLine"));
                    tshjTyxnJsList.add(tshjTyxnJs);
                }
            }
        }
        return tshjTyxnJsList;
    }


    /**
     * 切个获取的调压性能的电流电压曲线一半
     */
    private Map<String, ChartLineDTO> calFunc(DataTshjTyxn dataTshjTyxn) {
        //构造返回值
        Map<String, ChartLineDTO> ChartLineDTOMap = new HashMap<>();
        if (dataTshjTyxn == null) {
            return ChartLineDTOMap;
        }
        String isDl = dataTshjTyxn.getZhadl();
        List<Float> listX = isDl.equals("1") ? JSON.parseArray(dataTshjTyxn.getDlList(), Float.class) : JSON.parseArray(dataTshjTyxn.getDyList(), Float.class);
        List<Float> oil1List = JSON.parseArray(dataTshjTyxn.getYyList1(), Float.class);
        List<Float> oil2List = JSON.parseArray(dataTshjTyxn.getYyList2(), Float.class);
        float maxVel = Collections.max(listX);
        // 将最大值分割(找到最大值的索引)
        int index = listX.indexOf(maxVel);
        // 分割前半部分
        List<Float> listA1 = listX.subList(0, index);
        // 分割后半部分
        List<Float> listA2 = listX.subList(index, listX.size());
        //处理油压1数据
        if (null != oil1List && !oil1List.isEmpty()) {
            // 分割前半部分
            List<Float> listB1 = oil1List.subList(0, index);
            // 分割后半部分
            List<Float> listB2 = oil1List.subList(index, oil1List.size());
            Map<Float, Float> yy1BeforeMap = removeDuplicatesFunc(listA1, listB1);
            Map<Float, Float> yy1AfterMap = removeDuplicatesFunc(listA2, listB2);
            List<Float> yy1BeforeMapKeyList = new ArrayList<>(yy1BeforeMap.keySet());
            Collections.sort(yy1BeforeMapKeyList);
            List<Float> yy1BeforexVelList = new ArrayList<>();
            List<Float> yy1BeforeyVelList = new ArrayList<>();
            for (float key : yy1BeforeMapKeyList) {
                yy1BeforexVelList.add(key);
                yy1BeforeyVelList.add(yy1BeforeMap.get(key));
            }
            ChartLineDTOMap.put("yy1BeforeLine", BezierCurveUtil.calPoints(yy1BeforexVelList, yy1BeforeyVelList, false));
            List<Float> yy1AfterMapKeyList = new ArrayList<>(yy1AfterMap.keySet());
            Collections.sort(yy1AfterMapKeyList);
            List<Float> yy1AfterxVelList = new ArrayList<>();
            List<Float> yy1AfteryVelList = new ArrayList<>();
            for (float key : yy1AfterMapKeyList) {
                yy1AfterxVelList.add(key);
                yy1AfteryVelList.add(yy1AfterMap.get(key));
            }
            ChartLineDTOMap.put("yy1AfterLine", BezierCurveUtil.calPoints(yy1AfterxVelList, yy1AfteryVelList, false));
        }
        //处理油压2数据
        if (oil2List != null && !oil2List.isEmpty()) {
            // 分割前半部分
            List<Float> listC1 = oil2List.subList(0, index);
            // 分割后半部分
            List<Float> listC2 = oil2List.subList(index, oil2List.size());
            Map<Float, Float> yy2BeforeMap = removeDuplicatesFunc(listA1, listC1);
            Map<Float, Float> yy2AfterMap = removeDuplicatesFunc(listA2, listC2);
            List<Float> yy2BeforeMapKeyList = new ArrayList<>(yy2BeforeMap.keySet());
            Collections.sort(yy2BeforeMapKeyList);
            List<Float> yy2BeforexVelList = new ArrayList<>();
            List<Float> yy2BeforeyVelList = new ArrayList<>();
            for (float key : yy2BeforeMapKeyList) {
                yy2BeforexVelList.add(key);
                yy2BeforeyVelList.add(yy2BeforeMap.get(key));
            }
            ChartLineDTOMap.put("yy2BeforeLine", BezierCurveUtil.calPoints(yy2BeforexVelList, yy2BeforeyVelList, false));
            List<Float> yy2AfterMapKeyList = new ArrayList<>(yy2AfterMap.keySet());
            Collections.sort(yy2AfterMapKeyList);
            List<Float> yy2AfterxVelList = new ArrayList<>();
            List<Float> yy2AfteryVelList = new ArrayList<>();
            for (float key : yy2AfterMapKeyList) {
                yy2AfterxVelList.add(key);
                yy2AfteryVelList.add(yy2AfterMap.get(key));
            }
            ChartLineDTOMap.put("yy2AfterLine", BezierCurveUtil.calPoints(yy2AfterxVelList, yy2AfteryVelList, false));
        }
        return ChartLineDTOMap;
    }

    /**
     * 去重
     *
     * @param listA 电流 电压值
     * @param listB 油压值
     * @return
     */
    private Map<Float, Float> removeDuplicatesFunc(List<Float> listA, List<Float> listB) {
        Map<Float, Float> map = new HashMap<>();
        int size = Math.min(listA.size(), listB.size());
        for (int i = 0; i < size; i++) {
            float key = listA.get(i);
            float value = listB.get(i);
            if (map.containsKey(key)) {
                // 如果map中已经有该key，将对应的value取平均值
                float average = (map.get(key) + value) / 2;
                map.put(key, average);
            } else {
                map.put(key, value);
            }
        }
        return map;
    }


    /**
     * 合并电流电压点位
     * @param endYhYy1BeforeLine
     * @param endYhYy1AfterLine
     * @param endYhYy2BeforeLine
     * @param endYhYy2AfterLine
     * @param endEhYy1BeforeLine
     * @param endEhYy1AfterLine
     * @param endEhYy2BeforeLine
     * @param endEhYy2AfterLine
     * @return
     */
    private List<Float> mergeDldyList(ChartLineDTO endYhYy1BeforeLine, ChartLineDTO endYhYy1AfterLine,
                                      ChartLineDTO endYhYy2BeforeLine, ChartLineDTO endYhYy2AfterLine,
                                      ChartLineDTO endEhYy1BeforeLine, ChartLineDTO endEhYy1AfterLine,
                                      ChartLineDTO endEhYy2BeforeLine, ChartLineDTO endEhYy2AfterLine) {
        Set<Float> dldyList = new HashSet<>();
        if(null != endYhYy1BeforeLine) {
            for(int index = 0; index < endYhYy1BeforeLine.getLinePointList().size(); index++) {
                dldyList.add(endYhYy1BeforeLine.getLinePointList().get(index).x);
            }
        }
        if(null != endYhYy1AfterLine) {
            for(int index = 0; index < endYhYy1AfterLine.getLinePointList().size(); index++) {
                dldyList.add(endYhYy1AfterLine.getLinePointList().get(index).x);
            }
        }
        if(null != endYhYy2BeforeLine) {
            for(int index = 0; index < endYhYy2BeforeLine.getLinePointList().size(); index++) {
                dldyList.add(endYhYy2BeforeLine.getLinePointList().get(index).x);
            }
        }
        if(null != endYhYy2AfterLine) {
            for(int index = 0; index < endYhYy2AfterLine.getLinePointList().size(); index++) {
                dldyList.add(endYhYy2AfterLine.getLinePointList().get(index).x);
            }
        }
        if(null != endEhYy1BeforeLine) {
            for(int index = 0; index < endEhYy1BeforeLine.getLinePointList().size(); index++) {
                dldyList.add(endEhYy1BeforeLine.getLinePointList().get(index).x);
            }
        }
        if(null != endEhYy1AfterLine) {
            for(int index = 0; index < endEhYy1AfterLine.getLinePointList().size(); index++) {
                dldyList.add(endEhYy1AfterLine.getLinePointList().get(index).x);
            }
        }
        if(null != endEhYy2BeforeLine) {
            for(int index = 0; index < endEhYy2BeforeLine.getLinePointList().size(); index++) {
                dldyList.add(endEhYy2BeforeLine.getLinePointList().get(index).x);
            }
        }
        if(null != endEhYy2AfterLine) {
            for(int index = 0; index < endEhYy2AfterLine.getLinePointList().size(); index++) {
                dldyList.add(endEhYy2AfterLine.getLinePointList().get(index).x);
            }
        }
        List<Float> dldyResultList = new ArrayList<>(dldyList);
        Collections.sort(dldyResultList);
        float xEnd = getMin(endYhYy1BeforeLine.getMaxXLinePoint().x, endYhYy1AfterLine.getMaxXLinePoint().x, endYhYy2BeforeLine.getMaxXLinePoint().x, endYhYy2AfterLine.getMaxXLinePoint().x, endEhYy1BeforeLine.getMaxXLinePoint().x, endEhYy1AfterLine.getMaxXLinePoint().x, endEhYy2BeforeLine.getMaxXLinePoint().x, endEhYy2AfterLine.getMaxXLinePoint().x);
        float xStart = getMax(endYhYy1BeforeLine.getMinXLinePoint().x, endYhYy1AfterLine.getMinXLinePoint().x, endYhYy2BeforeLine.getMinXLinePoint().x, endYhYy2AfterLine.getMinXLinePoint().x, endEhYy1BeforeLine.getMinXLinePoint().x, endEhYy1AfterLine.getMinXLinePoint().x, endEhYy2BeforeLine.getMinXLinePoint().x, endEhYy2AfterLine.getMinXLinePoint().x);
        int start = dldyResultList.indexOf(xStart);
        int end = dldyResultList.indexOf(xEnd);
        return dldyResultList.subList(start, end);
    }

    private Float getMax(Float... xVels) {
        float velMax = Float.MIN_VALUE;
        for (Float vel : xVels) {
            if (vel != null) {
                velMax = Math.max(velMax, vel);
            }
        }
        return velMax;
    }

    private Float getMin(Float... xVels) {
        float velMin = Float.MAX_VALUE;
        for (Float vel : xVels) {
            if (vel != null) {
                velMin = Math.min(velMin, vel);
            }
        }
        return velMin;
    }

    private Float findYVel(ChartLineDTO line, float x) {
        Float yVel = null;
        for (LinePoint pointF : line.getLinePointList()) {
            if (pointF.x == x) {
                yVel = pointF.y;
                break;
            }
        }
        if (yVel == null) {
            yVel = BezierCurveUtil.getSelectPoints(line, x);
        }
        return yVel;
    }

    private Map<String, Float> findYyChzhFunc(List<Float> pointXList, ChartLineDTO yhyyLine1, ChartLineDTO yhyyLine2, ChartLineDTO ehyyLine1, ChartLineDTO ehyyLine2) {
        float yhyy = 0;
        float ehyy = 0;
        float chzhMax = Float.MIN_VALUE;
        float pointXVline = 0;
        for (Float pointX : pointXList) {
            float yhyy1 = findYVel(yhyyLine1, pointX);
            float yhyy2 = findYVel(yhyyLine2, pointX);
            float ehyy1 = findYVel(ehyyLine1, pointX);
            float ehyy2 = findYVel(ehyyLine2, pointX);
            float yhyyMax = Math.max(yhyy1, yhyy2);
            float yhyyMin = Math.min(yhyy1, yhyy2);
            float ehyyMax = Math.max(ehyy1, ehyy2);
            float ehyyMin = Math.min(ehyy1, ehyy2);
            yhyyMax = Math.round(yhyyMax * 1000f) / 1000f;
            yhyyMin = Math.round(yhyyMin * 1000f) / 1000f;
            ehyyMax = Math.round(ehyyMax * 1000f) / 1000f;
            ehyyMin = Math.round(ehyyMin * 1000f) / 1000f;
            float chzh1 = Math.abs(yhyyMax - ehyyMin);
            float chzh2 = Math.abs(ehyyMax - yhyyMin);
            float yhyyCache;
            float ehyyCache;
            float chzh;
            if (chzh1 > chzh2) {
                yhyyCache = yhyyMax;
                ehyyCache = ehyyMin;
                chzh = chzh1;
            } else {
                yhyyCache = yhyyMin;
                ehyyCache = ehyyMax;
                chzh = chzh2;
            }
            if (chzhMax < chzh) {
                chzhMax = chzh;
                yhyy = yhyyCache;
                ehyy = ehyyCache;
                pointXVline = pointX;
                log.info("TEST===> "+yhyy+","+ehyy+"," + pointXVline);
            }
        }
        float finalYhyy = yhyy;
        float finalEhyy = ehyy;
        float finalChzhMax = chzhMax;
        float finalPointXVline = pointXVline;
        return new HashMap<String, Float>() {{
            put("yhyy", finalYhyy);
            put("ehyy", finalEhyy);
            put("chzhMax", finalChzhMax);
            put("pointXVline", finalPointXVline);
        }};
    }


    /**
     * 查询提升机-调压性能测试
     *
     * @param dataTaskId 提升机-调压性能测试任务id
     * @return 提升机-调压性能测试
     */
    @Override
    public List<DataTshjTyxn> selectDataTshjTyxnByDataTaskId(Long dataTaskId) {
        return dataTshjTyxnMapper.selectDataTshjTyxnByDataTaskId(dataTaskId);
    }

    /**
     * 查询提升机-调压性能测试列表
     * 
     * @param dataTshjTyxn 提升机-调压性能测试
     * @return 提升机-调压性能测试
     */
    @Override
    public List<DataTshjTyxn> selectDataTshjTyxnList(DataTshjTyxn dataTshjTyxn)
    {
        return dataTshjTyxnMapper.selectDataTshjTyxnList(dataTshjTyxn);
    }

    /**
     * 新增提升机-调压性能测试
     * 
     * @param dataTshjTyxn 提升机-调压性能测试
     * @return 结果
     */
    @Override
    public int insertDataTshjTyxn(DataTshjTyxn dataTshjTyxn)
    {
        dataTshjTyxn.setCreateTime(DateUtils.getNowDate());
        return dataTshjTyxnMapper.insertDataTshjTyxn(dataTshjTyxn);
    }

    /**
     * 批量新增调压性能数据
     * @param dataTshjTyxns 提升机-调压性能测试
     * @return
     */
    @Override
    public int batchDataTshjTyxn(List<DataTshjTyxn> dataTshjTyxns) {
        return dataTshjTyxnMapper.batchDataTshjTyxn(dataTshjTyxns);
    }

    /**
     * 批量修改提升机-调压性能测试
     *
     * @param dataTshjTyxns 提升机-调压性能测试
     * @return 结果
     */
    @Override
    public int batchModifyDataTshjTyxn(List<DataTshjTyxnModify> dataTshjTyxns) {
        if(dataTshjTyxns != null && !dataTshjTyxns.isEmpty()) {
            //转换成数组
            dataTshjTyxns.forEach(item-> {
                item.setYyList1(Arrays.toString(item.getYyList1().split(",")));
                item.setYyList2(Arrays.toString(item.getYyList2().split(",")));
                item.setDlList(Arrays.toString(item.getDlList().split(",")));
                item.setDyList(Arrays.toString(item.getDyList().split(",")));
                dataTshjTyxnMapper.updateBatchDataTshjTyxn(item);
            });
        }
        return 1;
    }

    /**
     * 修改调压性能任务状态
     * @param dataTaskIds 调压任务id
     * @return
     */
    @Override
    public int updateDataTshjTyxnByDataTaskIds(Long[] dataTaskIds) {
        return dataTshjTyxnMapper.updateDataTshjTyxnByDataTaskIds(dataTaskIds);
    }

    /**
     * 修改提升机-调压性能测试
     * 
     * @param dataTshjTyxn 提升机-调压性能测试
     * @return 结果
     */
    @Override
    public int updateDataTshjTyxn(DataTshjTyxn dataTshjTyxn)
    {
        dataTshjTyxn.setUpdateTime(DateUtils.getNowDate());
        return dataTshjTyxnMapper.updateDataTshjTyxn(dataTshjTyxn);
    }

    /**
     * 变更调压性能任务状态为2
     * @param dataTaskId
     * @param tyxnId
     * @return
     */
    @Override
    public int updateDataTshjTyxnByTyxnId(Long dataTaskId, Long tyxnId) {
        return dataTshjTyxnMapper.updateDataTshjTyxnByTyxnId(dataTaskId, tyxnId);
    }

    /**
     * 批量删除提升机-调压性能测试
     * 
     * @param tyxnIds 需要删除的提升机-调压性能测试主键
     * @return 结果
     */
    @Override
    public int deleteDataTshjTyxnByTyxnIds(Long[] tyxnIds)
    {
        return dataTshjTyxnMapper.deleteDataTshjTyxnByTyxnIds(tyxnIds);
    }

    /**
     * 删除提升机-调压性能测试信息
     * 
     * @param tyxnId 提升机-调压性能测试主键
     * @return 结果
     */
    @Override
    public int deleteDataTshjTyxnByTyxnId(Long tyxnId)
    {
        return dataTshjTyxnMapper.deleteDataTshjTyxnByTyxnId(tyxnId);
    }
}
